package parts4.lesson46;

/**
 * 有趣的是Cloneable是个空接口,它表示了某种（克隆）能力
 */
public class Person implements Cloneable{
    private int age;
    public Person(){
        System.out.println("我来了");
    }

    @Override
    protected void finalize() throws Throwable {
        System.out.println("要被销毁了");
        //下面即便抛异常也是不会被执行的
        throw new Exception("我还要再活500年");
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person:"+this.age;
    }
}
